
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginForm extends JFrame {
    private JTextField usernameField;
    private JTextField passwordField;

    public LoginForm() {
        setTitle("Login");
        setSize(350, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);
        JButton loginButton = new JButton("Login");
        JButton sign_up = new JButton("Sign Up");
        //loginLabel.setFont(new Font("Arial", Font.BOLD, 24));
        sign_up.setHorizontalAlignment(JLabel.CENTER);
        sign_up.setVerticalAlignment(JLabel.CENTER);
        sign_up.addActionListener(actionEvent -> new SignupForm());
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        panel.add(loginButton, gbc);

        JLabel usernameLabel = new JLabel("Username:");
        usernameField = new JTextField(20);
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        panel.add(usernameLabel, gbc);
        gbc.gridx = 1;
        panel.add(usernameField, gbc);

        JLabel passwordLabel = new JLabel("Phone:");
        passwordField = new JTextField(20);
        gbc.gridx = 0;
        gbc.gridy = 2;
        panel.add(passwordLabel, gbc);
        gbc.gridx = 1;
        panel.add(passwordField, gbc);

        loginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String username = usernameField.getText();
                String phone = passwordField.getText();

                // You can validate the login here
                if (username.equals("Nahid") && phone.equals("01849680564")) {
                    JOptionPane.showMessageDialog(null, "Login successful!");
                    SwingUtilities.invokeLater(EmployeeEntryForm::new);
                } else {
                    JOptionPane.showMessageDialog(null, "Login failed. Please try again.");
                }
            }
        });
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.CENTER;
        panel.add(sign_up, gbc);

        add(panel);
        setVisible(true);
    }

}
